package com.artevivo.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.artevivo.entidades.Anyo;

@Repository
public class AnyoDAO extends AbstractDAO<Anyo, Long> {

    public AnyoDAO() {
        super();
    }

    @Autowired
    public AnyoDAO(SessionFactory sessionFactory) {
        super(sessionFactory);
    }

    @Transactional
    public Anyo findAnyobyAnyo(String anyo) {
        Session sesion = this.getSessionFactory().getCurrentSession();
        Anyo res = null;
        Criteria criteria = sesion.createCriteria(Anyo.class);
        criteria.add(Restrictions.eq("anyo", anyo));
        List<Anyo> any = criteria.list();
        if (any != null && !(any.isEmpty())) {
            res = any.get(0);
        }
        return res;
    }

}
